# 热题100 https://leetcode.cn/studyplan/top-100-liked/
# 5/100 双指针-盛最多水的容器
# leetcode第11题: https://leetcode.cn/problems/container-with-most-water/description/?envType=study-plan-v2&envId=top-100-liked
# Date: 2024/11/14

def maxArea(height: list[int]) -> int:
    """暴力法"""

    def volume(i: int, j: int):
        """计算容量的函数"""
        return min(height[i], height[j]) * abs(j - i)

    n, max_volume = len(height), 0
    for i in range(n - 1):
        for j in range(i + 1, n):
            max_volume = max(max_volume, volume(i, j))

    return max_volume


def maxArea_dbpnt(height: list[int]) -> int:
    """使用双指针的方法, l和r分别指向数组的两端向中间收缩"""

    def volume(i: int, j: int):
        """计算容量的函数"""
        return min(height[i], height[j]) * abs(j - i)

    l, r = 0, len(height) - 1
    max_volume = 0
    while l < r:
        max_volume = max(volume(l, r), max_volume)
        if height[l] < height[r]:
            l += 1
        else:
            r -= 1
    return max_volume


if __name__ == '__main__':
    print(maxArea([1, 8, 6, 2, 5, 4, 8, 3, 7]))  # 49
    print(maxArea_dbpnt([1, 8, 6, 2, 5, 4, 8, 3, 7]))  # 49
